home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / pi-5ways.zip / PI3.C < prev    next >
C/C++ Source or Header  |  1991-06-15  |  1KB  |  40 lines

  1. /**************************************************************************/
  2. /*              Calculate π by Leonhard Euler approximation               */
  3. /*   π ≈ √ { 6 ( 1/1 + 1/4 + 1/9 + 1/16 + 1/25 ... + 1/(n+1)**2 ...) }    */
  4. /*                                                                        */
  5. /*                                                                        */
  6. /*                              Mendel Cooper                             */
  7. /*                             3138 Foster Ave.                           */
  8. /*                           Baltimore, MD 21224                          */
  9. /*                                                                        */
  10. /*                                   06/91                                */
  11. /*                   Source code placed in the public domain              */                 
  12. /**************************************************************************/
  13.  
  14.  
  15. /*may need #include <math.h> */
  16.  
  17. #define MAX 5000
  18.  
  19. main()
  20. {
  21. double sqrt(),intermediate_result = 0,Pi;
  22. register int k;
  23.  
  24.  
  25.  
  26.  
  27. for (k = 0; k <= MAX; k++)
  28. {  
  29.       
  30.       intermediate_result += 1.0 / ( (k + 1.0) * (k + 1.0) );
  31.       Pi = sqrt( 6.0 * intermediate_result);
  32.  
  33.       printf("Term #%5d  ------->  π ≈ %f  \n",k,Pi);  }
  34.  
  35. }
  36.  
  37.  
  38.  
  39.  
  40.